Difference between long int and long long int in C/C++

您所在的位置:网站首页 long long int与long long Difference between long int and long long int in C/C++

Difference between long int and long long int in C/C++

2024-07-12 18:00| 来源: 网络整理| 查看: 265

All variables use data type during declarations to restrict the type of data to be stored. Therefore, we can say that data types are used to tell the variables the type of data it can store. Whenever a variable is defined in C++, the compiler allocates some memory for that variable based on the data type with which it is declared. Different data types require a different amount of memory.

Integer: The keyword used for integer data types is int. Integers typically require 4 bytes of memory space and range from -2147483648 to 2147483647.

Datatype Modifiers: As the name implies, datatype modifiers are used with the built-in data types to modify the length of data that a particular data type can hold. 

Below is a list of ranges along with the memory requirements and format specifiers on the 32-bit GCC compiler.

S. No. 

Data Type

Memory

(bytes)

Range

1 int 4 -2^31 to 2^31- 1 2 Long int 4 -2^31 to 2^31 – 1 3 Long long int 8 -2^63 to 2^63 – 1

 Long long takes the double memory as compared to long. But it can also be different on various systems. Its range depends on the type of application. The guaranteed minimum usable bit sizes for different data types:

char: 8 short:16 int: 16 long: 32 long long: 64

The decreasing order is: long long >=long>=int>=short>=char

Program 1:

In various competitive coding platforms, the constraints are between 107 to 1018. Below is the program to understand the concept:

C++

// C++ program to implement // the above approach #include using namespace std;   // Driver code int main() {     // Value of p 10^5     int p = 100000;       // Value of q 10^5     int q = 100000;       int result = p * q;     cout


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3